﻿using System;

namespace NodeJS.stream
{
    /// <summary>
    /// The Writable stream interface is an abstraction for a destination that you are writing data to.
    /// </summary>
    [ImportClass("", "require('stream').Writable")]
    public class Writable : EventEmitter, IWritable
    {
        /// <summary>
        /// In classes that extend the Writable class, make sure to call the constructor so that the buffering settings can be properly initialized.
        /// </summary>
        /// <param name="options">options Object
        /// <para>highWaterMark Number Buffer level when write() starts returning false. Default=16kb</para>
        /// <para>decodeStrings Boolean Whether or not to decode strings into Buffers before passing them to _write(). Default=true</para>
        /// </param>
        public Writable(object options = null)
        {
        }

        /// <summary>
        /// If a writable.write(chunk) call returns false, then the drain event will indicate when it is appropriate to begin writing more data to the stream.
        /// </summary>
        [EvalAtCompile(Value = "drain")]
        public const NodeEvent DRAIN = null;

        /// <summary>
        /// When the end() method has been called, and all data has been flushed to the underlying system, this event is emitted.
        /// </summary>
        [EvalAtCompile(Value = "finish")]
        public const NodeEvent FINISH = null;

        /// <summary>
        /// This is emitted whenever the pipe() method is called on a readable stream, adding this writable to its set of destinations.
        /// </summary>
        [EvalAtCompile(Value = "pipe")]
        public const NodeEvent<IReadable> PIPE = null;

        /// <summary>
        /// This is emitted whenever the unpipe() method is called on a readable stream, removing this writable from its set of destinations.
        /// </summary>
        [EvalAtCompile(Value = "unpipe")]
        public const NodeEvent<IReadable> UNPIPE = null;

        public virtual bool Write(StringOrBuffer chunk, string encoding = "", Action callback = null)
        {
            return false;
        }


        public virtual bool End(StringOrBuffer chunk = null, string encoding = "", Action callback = null)
        {
            return false;
        }
    }
}
